package offer.algorithm;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Description：
 * Author: zhangc
 * Date：2017/9/10 15:30
 */
public class UglyNum {

    public static int getUglyNumber(int index) {
        if (index <= 0)
            return 0;
        List<Integer> list = new ArrayList<>();
        list.add(1);
        int factor2 = 0, factor3 = 0, factor5 = 0;
        while (list.size() < index) {
            int n2 = list.get(factor2) * 2;
            int n3 = list.get(factor3) * 3;
            int n5 = list.get(factor5) * 5;
            int min = Math.min(n2, Math.min(n3, n5));
            list.add(min);
            if (min == n2)
                factor2++;
            if (min == n3)
                factor3++;
            if (min == n5)
                factor5++;
        }
        return list.get(list.size() - 1);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int index = scanner.nextInt();
        System.out.println(getUglyNumber(index));
    }
}
